<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initView()
    {
        $view = new Smarty_Smarty($this->getOption('smarty'));
        $view->headTitle()->setSeparator(' - ');
        $view->baseurl = BASE_URL;
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/system/system.ini', 'development');
        $scripts = $config->scripts->js;
        foreach($scripts as $script)
        {
            $view->headScript()->appendFile(BASE_URL.$script);
        }
        $styles = $config->styles->css;
        foreach($styles as $style)
        {
            $view->headLink()->appendStylesheet(BASE_URL. $style);
        }
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewRenderer->setViewSuffix('tpl');
        $viewRenderer->setView($view);
        $this->bootstrap('layout');
        $layout = Zend_Layout::getMvcInstance();
        $layout->setViewSuffix('tpl');
        return $view;
    }

    protected function _initDb()
    {
        $db = $this->getPluginResource('db')->getDbAdapter();
        $db->setFetchMode(Zend_Db::FETCH_ASSOC);
        $db->query("SET NAMES 'utf8'");
        $db->query("SET CHARACTER SET 'utf8'");
        Zend_Registry::set('db', $db);
        Zend_Db_Table::setDefaultAdapter($db);
        return $db;
    }
    protected function  _initRouters()
    {
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController ->getRouter();
        $router -> setGlobalParam("lang","vi");
        $router -> removeDefaultRoutes();
        $router -> addRoute(
            'langcontrolleraction',
            new Zend_Controller_Router_Route('/:lang/:controller/:action'
                ,array(
                    'lang' => ':lang',
                    'controller' => ':controller',
                )
            )
        );
        $router -> addRoute(
            'langindex',
            new Zend_Controller_Router_Route('/:lang/:controller'
                ,array(
                    'lang' => ':lang',
                    'controller' => 'index'
                )
            )
        );
    }
}